package com.rjs.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;

/**
 * 接收消息简单打印
 * @author LiuZhenghua
 * 2017年12月19日 上午10:16:42
 */
public class DiscardServerHandler extends ChannelInboundHandlerAdapter {

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
		try {
			ByteBuf buf = (ByteBuf)msg;
			while(buf.isReadable()) {
				System.out.print((char)buf.readByte());
			}
		} finally {
			ReferenceCountUtil.release(msg);
		}
	}
}
